<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>我的消息</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="../css/mui.min.css">

		<!--App自定义的css-->
<!--		<link rel="stylesheet" type="text/css" href="../css/app.css" />-->
		<link rel="stylesheet" type="text/css" href="../css/base2.css" />
		<!--<link rel="stylesheet" type="text/css" href="../css/Monitor.css" />
		<link rel="stylesheet" type="text/css" href="../css/iconfont.css" />-->
		<style>

		</style>
	</head>

	<div id="my-list">
		<div class="mui-input-row mui-search">
			<input type="search" id="searchInput" onkeyup="enterSearch(event)" class="mui-input-clear" placeholder="输入查询条件">
			<input id="value" hidden="true" />
		</div>
		<div class="list-t-wrap">
			<div id="pullrefresh" class="mui-scroll-wrapper">
				<ul class="mui-table-view">
				</ul>
				<!--<div class="mui-scroll" id="mui-table-view">
				</div>-->
			</div>
		</div>
		</body>
		<script src="../js/mui.min.js"></script>
		<script src="../js/wf.js"></script>
		<script src="../js/jquery-1.7.2.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/tools/template.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			mui.init({
				gestureConfig: {
					longtap: true
				},
				pullRefresh: {
					container: '#pullrefresh',
					down: {
						callback: pulldownRefresh
					},
					up: {
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}

			});
			var pagesize = 8;
			var page = 1;
			var TotalPage = 1;
			var userwhere="";
			var strWhere = "";
			mui.plusReady(function() {
				var self = plus.webview.currentWebview();
				var username = self.username;
				var userid = self.userid;
				userwhere="(SendUserID='"+self.username+"' or AccessUserID='"+self.username+"')";
				strWhere=userwhere;
				document.getElementById("value").value = self.value;
				//----------------右划事件------------------
				mui(".mui-table-view").on("swiperight", ".content_box", function() {
					var id = this.getAttribute("id");
					mui.openWindow({
						url: 'noticedetails.html',
						extras: {
							proid: id,
							username: username,
							value: self.value
						}
					});
				})

				//--------------------单击事件----------------
				mui(".mui-table-view").on('tap', '.content_box', function() {
					//记为已读
					var id = this.getAttribute("id");
					wf.ajax("Notice/NoticeReaded", {
								traditional: true,
								type: "get",
								data: {
									"noticeid": id,
									"value": self.value
								},
								dataType: "json",
								success: function(resule) {

								}
					});
					//打开具体项
						var objid = this.getAttribute("objid").split(","); 
						var typeid = this.getAttribute("typeid");
						var url="typeid";
						if(typeid==1){
							url="../material/matupdatedetail.html";
						}
						else if(typeid==2){
							url="../progress/progressupdatedetail.html";
						}
						else if(typeid==3){
							url="../safequality/safequalityupdatedetail.html";
						}
						else if(typeid==4){
							url="../business/businessupdatedetail.html";
						}
						mui.openWindow({
							url: url,
							extras: {
								proid: objid[0],
								username: username,
								mid: objid[1],
								bid: objid[1],
								pid: objid[1],
								sid: objid[1],
								value: self.value
							}
						});
					})
				
					//长按事件----------------------------------------
				mui(".mui-table-view").on('longtap', '.content_box', function() {
					var id = this.getAttribute("id");
					var btnArray = ['否', '是'];
					mui.confirm('删除不可恢复，确认？', '删除该信息', btnArray, function(e) {
						if(e.index == 1) {
							plus.nativeUI.showWaiting();
							wf.ajax("Notice/NoticeReaded", {
								traditional: true,
								type: "get",
								data: {
									"noticeid": id,
									"value": self.value
								},
								dataType: "json",
								success: function(resule) {
									if(resule.Code == "20000") {
										plus.nativeUI.closeWaiting();
										mui.toast(resule.Msg);
										location.reload();
									} else {
										plus.nativeUI.closeWaiting();
										mui.toast(resule.Msg);
									}
								}
							});
						} else {
							return;
						}
					})
				})
			});

			/**
			 * 下拉刷新具体业务实现
			 */
			function pulldownRefresh() {
				setTimeout(function() {
					pagesize = 8;
					page = 1;
					TotalPage = 1;
					$(".mui-table-view").empty();
					mui('#pullrefresh').pullRefresh().endPullupToRefresh((page > TotalPage));
					loaddata(strWhere, page++, pagesize);
					mui('#pullrefresh').pullRefresh().endPulldownToRefresh(); //refresh completed
				}, 1500);
			}
			/**
			 * 上拉加载具体业务实现
			 */
			function pullupRefresh() {
				setTimeout(function() {
					mui('#pullrefresh').pullRefresh().endPullupToRefresh((page > TotalPage)); //参数为true代表没有更多数据了。
					// 加载更多的内容到列表中
					if(page <= TotalPage) {
						loaddata(strWhere, page++, pagesize);
					}
				}, 1500);
			}
			if(mui.os.plus) {
				mui.plusReady(function() {
					setTimeout(function() {
						mui('#pullrefresh').pullRefresh().pullupLoading();
					}, 1000);

				});
			} else {
				mui.ready(function() {
					mui('#pullrefresh').pullRefresh().pullupLoading();
				});
			}

			function loaddata(strWhere, page, pagesize, value) {
				value = (document.getElementById("value").value);
				plus.nativeUI.showWaiting();
				wf.ajax("Notice/NoticeList", {
					traditional: true,
					type: "get",
					data: {
						"value": value,
						"strWhere": strWhere,
						"page": page,
						"pagesize": pagesize,
						"orderby": "NoticeID"
					},
					dataType: "json",
					success: function(resule) {
						if(resule.Code == "20000") {
							plus.nativeUI.closeWaiting();
							var obj = JSON.parse(resule.Data);
							TotalPage = Math.ceil(obj.Total / pagesize);
							var data = {
								data: obj.DataList
							};

							$(".mui-table-view").append(template('tempNoticeList', data));
						} else {
							plus.nativeUI.closeWaiting();
//							mui.toast(resule.Msg);
						}
					}
				});
			}

			function enterSearch(e) {
				if(e.keyCode == 13) {
					document.body.querySelector('#searchInput').blur();
					setTimeout(function() {
						var inputstr = document.body.querySelector('#searchInput').value;
						pagesize = 8;
						page = 1;
						TotalPage = 1;
						strWhere = userwhere+" and Content like '%" + inputstr + "%'";
						$(".mui-table-view").empty();
						//mui('#pullrefresh').pullRefresh().endPullupToRefresh((page>TotalPage));
						loaddata(strWhere, page++, pagesize);
						//mui('#pullrefresh').pullRefresh().endPulldownToRefresh(); //refresh completed
					}, 1500);
				}
			}
		</script>

		<script id="tempNoticeList" type="text/html">
			<%for(var i=0;i<data.length;i++){%>
				<li class="mui-table-view-cell mui-media content_box" id="<%=data[i].NoticeID%>" objid="<%=data[i].ObjID%>" typeid="<%=data[i].TypeID%>">
					<a href="javascript:;">
						<img class="mui-media-object mui-pull-right" src="http://192.168.0.108/FileUpload/ReadPic?name=User_<%=data[i].SendUserID%>" />
						<div class="mui-media-body">
							<%=data[i].Title%>
							<%if(data[i].NoticeStatus==1){%>
							<span class="mui-icon mui-icon-email"></span>
							<%}%>
							<p class="mui-ellipsis"><%=data[i].Content%></p>
						</div>
					</a>
				</li>

			<%}%>

		</script>

</html>